package com.yd.sdk.adpangle;

import android.app.Activity;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.util.Log;

import com.bytedance.sdk.openadsdk.TTAdConfig;
import com.bytedance.sdk.openadsdk.TTAdSdk;
import com.yd.sdk.IUnityActivityLifecycleEvents;

public class AdPangleImp implements IUnityActivityLifecycleEvents {
    private static String TAG = "AdPangleImp";
    private Activity _activity;
    @Override
    public void onCreate(Activity activity, Bundle savedInstanceState) {
        _activity = activity;
        TTAdSdk.init(activity, buildConfig(), new TTAdSdk.InitCallback() {
            @Override
            public void success() {
                //load pangle ads after this method is triggered.
                Log.e(TAG,"success");
            }

            @Override
            public void fail(int code, String msg) {
                Log.e(TAG,code +",message:" + msg);
            }
        });
    }

    private TTAdConfig buildConfig() {
        try{
            ApplicationInfo appInfo = _activity.getPackageManager().getApplicationInfo(_activity.getPackageName(), PackageManager.GET_META_DATA);
            int appId = appInfo.metaData.getInt("com.yd.sdk.pangleID");
            return new TTAdConfig.Builder()
                    .appId(appId +"")
                    .supportMultiProcess(false)
                    .coppa(0) //CoppaValue: 0 adult, 1 child
                    .build();
        }
        catch (Exception e)
        {

        }

        return null;
    }

    @Override
    public void onPause() {

    }

    @Override
    public void onResume() {

    }

    @Override
    public void onDestroy() {

    }

    @Override
    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantRes) {

    }
}
